<?php

	namespace org\tekuna\demo\weblog\action;
	
	use \PDOException;
	
	use org\tekuna\demo\weblog\manager\ArticleManager;
	
	use org\tekuna\framework\request\Request;
	use org\tekuna\framework\action\ActionEvent;
	
	use org\tekuna\plugin\simpletemplate\SimpleTemplateAction;
	
	
	class ListArticlesAction extends SimpleTemplateAction {
		
		private $objArticleManager;
		
		protected
			$arrArticles = array();
		
		
		public function executeTemplate(ActionEvent $objActionEvent, Request $objRequest) {
			
			try {
				
				// load all articles to the array
				// TODO: pagination
				$this -> arrArticles = $this -> objArticleManager -> getAllArticles();
			}
			catch (PDOException $objException) {
				
				// nothing, handled in template when no articles found.
			}
		}
		
		public function setArticleManager(ArticleManager $objArticleManager) {
			
			$this -> objArticleManager = $objArticleManager;
		}
	}
